<?php

require('funcs.php');

define("TEMPLATE_FILE", "derivedTemp.php");
define("OUTPUT_DIR", "../");

$defineFiles = array(
    "11.php", "12.php", "13.php", "14.php", "15.php", "16.php", "17.php",
);

$IDs='';
$content=file_get_contents(TEMPLATE_FILE);

foreach ( $defineFiles as $defineFile ) {
    $definitions=require($defineFile);
    foreach ($definitions as $def)
    {
        $effects='';
        foreach($def['effects'] as $effect) {
            $effects .= $effect;
        }
    
	    file_put_contents(OUTPUT_DIR."PetSkill_${def['id']}.php", 
		    strtr($content, 
			    array(
				    '{ID}'=>$def['id'],
				    '{Name}'=>$def['name'],
				    '{Desc}'=>isset($def['desc'])?$def['desc']:'',
				    '{Mp}'=>$def['mp'],
				    '{SuccRatio}'=>$def['succRatio'],
				    '{Effects}'=>$effects,
                    '{LevelMax}'=>isset($def['levelMax'])?$def['levelMax']:4,
			    )
		    )
	    );
	    $IDs.="${def['id']}=>1,";
    }
}

$content=file_get_contents('baseTemp.php');
file_put_contents(OUTPUT_DIR."PetSkill.php",
	strtr($content,
		array(
			'{IDs}'=>$IDs,
		)
	)
);

?>
